const registerBtn = document.querySelector('#btn-register');


registerBtn.addEventListener('click', async function (e) {
    const username = document.querySelector('input[name="username"]').value.trim();
    const password = document.querySelector('input[name="password"]').value.trim();

    if (!username || !password) {
        document.querySelector('#myToast .toast-body').innerHTML = "用户名密码不能为空"
        myToast.show()
    }

    const res = await axios({
        url: '/register',
        method: 'post',
        data: {
            username,
            password
        }
    })
    if (res.data.message === "注册成功") {
        document.querySelector('#myToast .toast-body').innerHTML = "注册成功"
        myToast.show()
        setInterval(() => {
            location.href = "./login.html"
        }, 1500);
    }
})